

$(document).ready(function () {
    init( callback, 1);
});


function init( callback, current) {
    $("#thislist").html("");
    $.ajax({
        type: "get",
        url: urlcore + "/api/buyTogetherGoods/selectPage?current=" + current ,
        dataType: "json",
        headers: {"Content-Type": "application/json;charset=UTF-8"},
        data: {},
        success: function (data) {//data是返回的hash,key之类的值，key是定义的文件名
            if (data.success == true) {
                callback(data.data.records);
                $('#thiscount').text(data.data.total);
                $("#pager").pager({
                    pagenumber: current,
                    pagecount: data.data.pages,
                    totalcount: data.data.total,
                    buttonClickCallback: PageClick
                });
            } else {
                alert(data.msg);
            }
        },
        error: function () {
            alert("获取列表失败");
        }
    });

}


//回调函数  
PageClick = function (pageclickednumber) {
    init( callback, pageclickednumber);
}

var callback = function (data) {
    var html = "", goodsName = "", goodsType = "", goodsUrl = "", mPrice="",buyTogetherPrice = "",needTogetherNum="",buyTogetherLimitTime="";
    for (var i = 0; i < data.length; i++) {
        id = data[i].id;
        goodsName = data[i].goods.goodsName;
        goodsUrl = data[i].goods.goodsUrl != null ? data[i].goods.goodsUrl : "";
        mPrice = data[i].goods.mPrice;

        gmtDatetime = data[i].gmtDatetime != null ? new Date(data[i].gmtDatetime).pattern("yyyy-MM-dd hh:mm:ss") : "";
     html +=    "  <tr>\n" +   
	            " <td>" + (i + 1) + "</td>\n" +
	            " <td>" + goodsName + "</td>\n" +
	            " <td>" + mPrice + "</td>\n" +
	            " <td>" + data[i].buyTogetherPrice + "</td>\n" +
	            "<td class=\"footable-visible\"><img width=\"40px\" height=\"40px\" src=\"" + goodsUrl + "\"></td>\n" +
	            "<th>" + data[i].needTogetherNum + "</th>\n" +
	            " <th>" + data[i].buyTogetherLimitTime + "</th>\n" +
	            " <td>\n" +
	            " <a class=\"btn btn-danger btn-xs\" href=\"javascript:;\" onclick=\"doDelete(" + id + ")\"> 删除</a>\n" 
	            " </td>\n" +
	            " </tr>";
    }
    $("#thislist").append(html);
}


//刪除
function doDelete(id) {
	var flag=confirm("确定要删除该商品吗？删除后正在参团的会员购买费用将原路退还。");
	if(flag){
		 $.ajax({
        type: "GET",
        url: urlcore + "/api/buyTogetherGoods/deleteBugTogetherGoods?id=" + id,
        dataType: "json",
        headers: {"Content-Type": "application/json;charset=UTF-8"},
        data: {},
        success: function (data) {//data是返回的hash,key之类的值，key是定义的文件名
            if (data.success == true) {
                location.reload();
            } else {
                alert(data.msg);
            }
        },
        error: function () {
            alert("删除失败");
        }
    });
	}

   
}









//搜索
function searchuser() {
    var type = $('#goods_type option:selected').val();//选中的值
    init(type, callback, 1);
}







